AC_PREREQ([2.69])

AC_INIT([TailorNG], [0.0], [dlsi.ua.es])

AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_BUILD

AM_INIT_AUTOMAKE([-Wall -Werror subdir-objects])
AM_AUTOMAKE_VERSION([1.14])
AM_SILENT_RULES

AC_CONFIG_FILES([Makefile
				include/Makefile
				include/utils/Makefile
				include/RepoTemplate/Makefile
				lib/Makefile
				lib/dotwriter/Makefile
				lib/utils/Makefile
				lib/libsvn/Makefile
				lib/libbzr/Makefile
				lib/libgit/Makefile
				lib/libcvs/Makefile
				share/Makefile
				src/Makefile
				])
				
# Checks for programs.
AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX_11([ext],[mandatory])

AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

AM_PROG_CC_C_O
AM_PROG_AR

AC_PROG_SED
#AC_PROG_LEX
#AC_PROG_YACC
AX_PROG_BISON([],[AC_MSG_ERROR(did not find bison)])
AX_PROG_FLEX([],[AC_MSG_ERROR(did not find flex)])

AC_PROG_LIBTOOL

LT_PREREQ([2.4])
LT_INIT([shared])

AC_SUBST([GIT])
AC_PATH_PROG([GIT], [git], [no])
if test "$GIT" = no; then
  AC_MSG_ERROR(did not find git)
fi;

AC_SUBST([SVN])
AC_PATH_PROG([SVN], [svn], [no])
if test "$SVN" = no; then
  AC_MSG_ERROR(did not find svn)
fi;

AC_SUBST([CVS2CL])
AC_PATH_PROG([CVS2CL], [cvs2cl],[no])
if test "$CVS2CL" = no; then
  AC_MSG_ERROR(did not find cvs2cl)
fi;

AC_SUBST([CVS])
AC_PATH_PROG([CVS], [cvs], [no])
if test "$CVS" = no; then
  AC_MSG_ERROR(did not find cvs)
fi;

AC_SUBST([BZR])
AC_PATH_PROG([BZR], [bzr], [no])
if test "$BZR" = no; then
  AC_MSG_ERROR(did not find bzr)
fi;


AC_SUBST([TESTTOOL])
AC_PATH_PROG([TESTTOOL], [testool], [no])
if test "$TESTTOOL" = no; then
  AC_MSG_WARN(did not find testool)
fi;

# Checks for libraries.
PKG_CHECK_MODULES([LIBCONFIGXX], [libconfig++ >= 1.4], AC_MSG_NOTICE([module libconfig found]), AC_MSG_FAILURE([libconfig++ 1.4 or newer not found.]))
PKG_CHECK_MODULES([LIBXMLXX], [libxml++-2.6 >= 2.10.0], AC_MSG_NOTICE([module libxml++ found]), AC_MSG_FAILURE([libxml++-2.6 2.10 or newer not found.]))
PKG_CHECK_MODULES([LIBGLOG], [libglog >= 0.3], AC_MSG_NOTICE([module libglog found]),AC_MSG_FAILURE([libglog 0.3 or newer not found]))
PKG_CHECK_MODULES([LIBGFLAGS], [libgflags >= 2.0],AC_MSG_NOTICE([module libgflags found]),AC_MSG_FAILURE([libgflags 2.0 or newer not found]))
PKG_CHECK_MODULES([LIBGIT2], [libgit2 >= 0.19],AC_MSG_NOTICE([module libgit2 found]),AC_MSG_FAILURE([libgit2 0.19 or newer not found]))

AC_SUBST(LIBCONFIGXX_CFLAGS)
AC_SUBST(LIBCONFIGXX_LIBS)

AC_SUBST(LIBXMLXX_CFLAGS)
AC_SUBST(LIBXMLXX_LIBS)

AC_SUBST(LIBGLOG_CFLAGS)
AC_SUBST(LIBGLOG_LIBS)

AC_SUBST(LIBGFLAGS_CFLAGS)
AC_SUBST(LIBGFLAGS_LIBS)

# Checks for header files.
AC_CHECK_HEADERS

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT8_T
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memset setlocale])


CPPFLAGS="$CPPFLAGS -Wall -Wshadow -Wextra -pedantic -ggdb"
AC_OUTPUT

echo \ 
"------------------------------------------------- 
${PACKAGE_NAME} Version ${PACKAGE_VERSION} 
Prefix: '${prefix}'. 
Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}' 

GIT 	: 	${GIT}
BZR 	: 	${BZR}
SVN 	: 	${SVN}
CVS 	: 	${CVS}
CVS2CL 	: 	${CVS2CL}
SED 	: 	${SED}
BISON	:	${YACC}
FLEX	:	${LEX}

Now type 'make @<:@<target>@:>@'
where the optional <target> is: 
   all - build all binaries 
   install - install everything 
--------------------------------------------------"